home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-04 | 6.5 KB | 256 lines | [TEXT/KAHL] |
- /********************************************************* DEFINITION
- DATE: 9/23/93
- AUTHOR: Eric R. Rosé
-
- CLASS: CPPControl
-
- SUPERCLASS: CPPVisualObject
-
- This C++ class manages a Button control
-
- ********************************************************************/
-
- #include <CPPControl.h>
- #include <CPPWindow.h>
-
- extern Rect kDefaultRect;
- extern Rect kEmptyRect;
-
- /*-----------------------------------------------------------------*/
- /*------------------------ PUBLIC METHODS -------------------------*/
- /*-----------------------------------------------------------------*/
-
- CPPControl::CPPControl (CPPWindow *itsWindow, short ResID,
- Boolean isFramed,
- Boolean canBeTarget,
- Boolean active, Boolean visible) :
- CPPVisualObject (itsWindow, &kDefaultRect, canBeTarget,
- active, visible)
- /* load a control resource and initialize with the given data */
- {
-
- if (this->owningWindow)
- {
- this->theControl = GetNewControl (ResID, this->owningWindow);
- this->hasFrame = isFramed;
- this->isEnabled = TRUE;
- this->myValue = 0;
- }
- this->callBackProc = NULL;
- }
-
- /*-----------------------------------------------------------------*/
-
- CPPControl::CPPControl (CPPWindow *itsWindow, Rect *itsBounds,
- short ControlType, StringPtr itsText,
- Boolean isFramed,
- Boolean useWindowFont,
- Boolean canBeTarget,
- Boolean active, Boolean visible) :
- CPPVisualObject (itsWindow, itsBounds, canBeTarget,
- active, visible)
- {
- short procid = (useWindowFont) ? ControlType | 8 : ControlType;
-
- if (this->owningWindow)
- this->theControl =
- NewControl(this->owningWindow, itsBounds, itsText,
- visible, 0, 0, 1, procid, 13);
- this->hasFrame = isFramed;
- this->isEnabled = TRUE;
- this->myValue = 0;
- this->callBackProc = NULL;
- }
-
- /*-----------------------------------------------------------------*/
-
- CPPControl::~CPPControl (void)
- {
- if (this->theControl)
- DisposeControl(this->theControl);
- }
-
- /*-----------------------------------------------------------------*/
-
- char *CPPControl::ClassName (void)
- {
- return "CPPControl";
- }
-
- /*-----------------------------------------------------------------*/
-
- Boolean CPPControl::DoClick (EventRecord *theEvent)
- /* handle a click in the control - if visible */
- {
- Point myPt = theEvent->where;
-
- if (this->theControl && this->IsVisible() && this->isEnabled)
- {
- Global2Local (&myPt);
- if (TrackControl(this->theControl, myPt, this->callBackProc))
- DoOnClick ();
- return TRUE;
- }
-
- return FALSE;
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPControl::Activate (Boolean nowActive)
- /* activate/deactivate our control */
- /* SUBCLASS SHOULD OVERRIDE */
- {
- // controls do not usually change their appearance
- // when in background or foreground
-
- CPPVisualObject::Activate(nowActive);
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPControl::MakeVisible (Boolean nowVisible)
- /* hide/show our control */
- /* IS OVERRIDE */
- {
- if (this->theControl)
- {
- if (nowVisible)
- ShowControl (this->theControl);
- else
- HideControl (this->theControl);
- }
-
- CPPVisualObject::MakeVisible(nowVisible);
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPControl::Draw ()
- /* is override */
- {
- PenState OldState;
- Rect frameRect = *GetBounds();
-
- if (this->IsVisible() && this->theControl)
- {
- Draw1Control (theControl);
- if (this->hasFrame)
- FrameControl(GetCVariant(this->theControl) == pushButProc);
- }
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPControl::FrameControl (Boolean useRoundRect)
- /* draw the standard 3-pixel wide border around the control */
- {
- PenState OldState;
- Rect frameRect = *GetBounds();
-
- GetPenState(&OldState);
- InsetRect(&frameRect, -4, -4);
- PenPat(black);
- PenSize (3,3);
- if (useRoundRect)
- FrameRoundRect(&frameRect, 16, 16);
- else
- FrameRect (&frameRect);
- SetPenState(&OldState);
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPControl::SetValue (short newValue)
- /* set the control's value to the value passed to us */
- /* SUBCLASS MAY OVERRIDE */
- {
- SetCtlValue (this->theControl, this->myValue = newValue);
- }
-
- /*-----------------------------------------------------------------*/
-
- short CPPControl::GetValue (void)
- /* return the value of the control */
- {
- return this->myValue;
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPControl::SetCallBack (ProcPtr callBack)
- {
- this->callBackProc = callBack;
- }
-
- /*-----------------------------------------------------------------*/
-
- Boolean CPPControl::IsEnabled (void)
- {
- return this->isEnabled;
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPControl::DoOnClick (void)
- /* perform some action when the control is clicked */
- /* SUBCLASS SHOULD OVERRIDE */
- {
- if (this->doClickProc) // call the user-specified click handler
- (doClickProc)(this->owningWObject);
- else
- if (this->commandEquivalent != kNoCommand)
- this->owningWObject->DoCommand (this->commandEquivalent);
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPControl::EnableControl (Boolean nowEnabled)
- {
- if (this->theControl)
- {
- if (nowEnabled != this->isEnabled)
- {
- InvalRect (GetBounds());
- this->isEnabled = nowEnabled;
- HiliteControl (this->theControl, (nowEnabled) ? 0 : 255);
- }
- }
- }
-
- /*-----------------------------------------------------------------*/
-
- Rect *CPPControl::GetBounds (void)
- /* return the boundsrect of the object */
- /* SUBCLASS MUST OVERRIDE */
- {
- if (this->theControl && this->IsVisible())
- this->bounds = (*this->theControl)->contrlRect;
- else
- this->bounds = kEmptyRect;
-
- return &this->bounds;
- }
-
- /*-----------------------------------------------------------------*/
- /*---------------------- PROTECTED METHODS ------------------------*/
- /*-----------------------------------------------------------------*/
-
- void CPPControl::MoveContent (short newH, short newV)
- /* move the entire button to a new position */
- {
- if (this->theControl)
- MoveControl (this->theControl, newH, newV);
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPControl::ResizeContent (short newWidth, short newHeight)
- /* change the size of the button */
- {
- if (this->theControl)
- SizeControl(this->theControl, newWidth, newHeight);
- }
-
-
-